package com.example.task;

import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * Created by Administrator on 2017/1/14 0014.
 */


/**
 * 定义3个任务
 * @author Angel(QQ:412887952)
 * @version v.0.1
 */

@Component
public class AsyncTask1 {

    //定义一个随机对象.
    public static Random random =new Random();

    //任务一;
    public void doTaskOne() throws Exception {
        System.out.println("开始做任务一");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务一，耗时：" + (end - start) + "毫秒");
    }

    //任务二;
    public void doTaskTwo() throws Exception {
        System.out.println("开始做任务二");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务二，耗时：" + (end - start) + "毫秒");
    }

    //任务3;
    public void doTaskThree() throws Exception {
        System.out.println("开始做任务三");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务三，耗时：" + (end - start) + "毫秒");
    }

}
